﻿using Easy.Domain.Abstractions;
using Easy.Domain.Events;
using System;
using System.Collections.Generic;
using System.Text;

namespace Easy.Domain.OrderAggregate
{
    public class Order:Entity<long>,IAggregateRoot
    {
        public string UserId { get; private set; }
        public string UserName { get; private set; }
        public Address Address { get; private set; }
        public int ItemCount { get; private set; }

        protected Order() { }
        public Order(string userId,string userName,int itemCount,Address address)
        {
            UserId = UserId;
            UserName = userName;
            this.ItemCount = ItemCount;
            this.Address = address;

            //领域事件由领域模型定义，通过领域业务逻辑来触发，实现定义在应用层
            this.AddDomainEvent(new OrderCreateDomainEvent(this));
        }

        public void ChangeAddress(Address address)
        {
            this.Address = address;
            //this.AddDomainEvent(new AddressChangedDomainEvent(this));
        }
    }
}
